package com.lbd.finance.controller;

import com.lbd.base.controller.BaseController;
import com.lbd.commons.Result;
import com.lbd.commons.ResultState;
import com.lbd.finance.bean.vo.ExportInvestFlowDetailVo;
import com.lbd.finance.bean.vo.InvestFlowDetailVo;
import com.lbd.finance.service.InvestFlowDetailService;
import com.lbd.util.ExcelExportUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("/investFlowDetail")
public class InvestFlowDetailController extends BaseController {
    private final Logger log = Logger.getLogger(this.getClass());

    @Autowired
    private InvestFlowDetailService investFlowDetailService;

    /**
     * 时间筛选条件格式，重新定义
     * @param webDataBinder webDataBinder
     * @throws Exception
     */

    /**
     * 按条件分页查询投资流水信息
     *
     * @param page               第几页
     * @param rows               一页多少条
     * @param investFlowDetailVo
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result list(int page, int rows, InvestFlowDetailVo investFlowDetailVo) {
        return new Result(ResultState.SUCCESS, "查询成功", investFlowDetailService.getInvestFlowDetailList(page, rows, investFlowDetailVo));
    }


    /**
     * 导出投资信息
     *
     * @param request            request
     * @param response           response
     * @param investFlowDetailVo 查询条件
     */
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public void export(HttpServletRequest request, HttpServletResponse response, InvestFlowDetailVo investFlowDetailVo) {

        List<ExportInvestFlowDetailVo> exportList = investFlowDetailService.getExportInvesetFlowList(investFlowDetailVo);
        if (CollectionUtils.isNotEmpty(exportList)) {
            ExcelExportUtils.exportExcel(request, response, DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"), ExportInvestFlowDetailVo.class, exportList);
        }

    }


}
